package com.example.a2205_fx.video;

import androidx.lifecycle.MutableLiveData;

import com.example.a2205_fx.base.BaseViewModel;
import com.example.a2205_fx.entity.PinglunEntity;
import com.example.a2205_fx.entity.ResultEntity;
import com.example.a2205_fx.entity.VideoEntity;
import com.example.a2205_fx.util.Cons;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class VideoViewModel extends BaseViewModel<VideoRepo> {
    @Override
    protected VideoRepo createRepo() {
        return new VideoRepo();
    }
    public MutableLiveData<VideoEntity> success = new MutableLiveData<>();
    public MutableLiveData<String> fail = new MutableLiveData<>();
    public void video(int page,int size){
        repo.video(page,size,success,fail);
    }

    public MutableLiveData<ResultEntity> loveSuccess = new MutableLiveData<>();
    public MutableLiveData<String> loveFail = new MutableLiveData<>();
    public void love(int videoId){
        repo.love(videoId,loveSuccess,loveFail);
    }

    public MutableLiveData<ResultEntity> noloveSuccess = new MutableLiveData<>();
    public MutableLiveData<String> noloveFail = new MutableLiveData<>();

    public void nolove(int videoId){
        repo.nolove(videoId,noloveSuccess,noloveFail);
    }

    public MutableLiveData<PinglunEntity> getSuccess = new MutableLiveData<>();
    public MutableLiveData<String> getFail = new MutableLiveData<>();
    public void getComment(int videoId){
        repo.getComment(videoId,getSuccess,getFail);
    }

    public MutableLiveData<PinglunEntity> comSucc = new MutableLiveData<>();
    public MutableLiveData<String> comFail = new MutableLiveData<>();

    public void comment(String msg,int videoId){
        Map<String,String> map = new HashMap<>();
        map.put("videoId",videoId+"");
        map.put("msg",msg);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Cons.MEDIA_TYPE),json);
        repo.comment(body,comSucc,comFail);
    }
}
